package cn.wsalix.spring.utils;

import java.util.Date;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.wsalix.admin.entity.RequiresPermit;
import cn.wsalix.admin.repository.RequiresPermitRepository;
@Component("requiresPermissionsTraverse")
public class RequiresPermissionsTraverse implements Traverse<RequiresPermissions> {
	@Autowired
	private RequiresPermitRepository requiresPermitRepository;
	@Override
	public void process(RequiresPermissions annotation) {	
		for(String permit:annotation.value()){
			RequiresPermit requiresPermit=new RequiresPermit();
			requiresPermit.setCode(permit);
			requiresPermit.setCreatedDate(new Date());// DateTime.now());
			requiresPermit.setCreatedBy(0l);
			requiresPermitRepository.save(requiresPermit);
		}	
	}

}
